***************** Presidential, but not prime minister, candidates with lower-pitched voices **********************************
******************  stand a better chance of winning the election in conservative countries ***********************************

*************************************FORTHCOMING IN EVOLUTIONARY PSYCHOLOGY****************************************************

*--------------------------------------------REPLICATION FILES----------------------------------------------------------------*

*                                            RECODES VARIABLES                                                                *

** Recodes Election type
recode El_type (1=0) (2=1)
label define El_typeLB 0 "Presidential" 1 "Parliamentary"
label values El_type El_typeLB


*** Summary statistics for Ideology and candidates' percentage of votes received
summ Score if El_outcome == 1
summ Score if El_outcome == 0
summ Percentage if El_outcome


** Creates variable for dyadic electoral contests (groups of two candidates competing against each other)
* Coded based on variable "NO" such that competing candidates have same number as in "NO" just without the letter.
* Moreover, when there is both a set of observations from a presidential and a general election for a given country Dyades are coded ///
// with three numbers such that the last number refers to the presidential or the general election contest (for instance Poland, "NO"=23)
generate Dyades =.
replace Dyades = 1 if NO=="01A" | NO=="01B"
replace Dyades = 2 if NO=="02A" | NO=="02B"
replace Dyades = 3 if NO=="03A" | NO=="03B"
replace Dyades = 4 if NO=="04A" | NO=="04B"
replace Dyades = 5 if NO=="05A" | NO=="05B"
replace Dyades = 6 if NO=="06A" | NO=="06B"
replace Dyades = 7 if NO=="07A" | NO=="07B"
replace Dyades = 8 if NO=="08A" | NO=="08B"
replace Dyades = 10 if NO=="10A" | NO=="10B"
replace Dyades = 11 if NO=="11A" | NO=="11B"
replace Dyades = 12 if NO=="12A" | NO=="12B"
replace Dyades = 13 if NO=="13A" | NO=="13B"
replace Dyades = 14 if NO=="14A" | NO=="14B"
replace Dyades = 15 if NO=="15A" | NO=="15B"
replace Dyades = 16 if NO=="16A" | NO=="16B"
replace Dyades = 17 if NO=="17A" | NO=="17B"
replace Dyades = 18 if NO=="18A" | NO=="18B"
replace Dyades = 19 if NO=="19A" | NO=="19B"
replace Dyades = 20 if NO=="20A" | NO=="20B"
replace Dyades = 21 if NO=="21A" | NO=="21B"
replace Dyades = 22 if NO=="22A" | NO=="22B"
replace Dyades = 231 if NO=="23A" | NO=="23B"
replace Dyades = 232 if NO=="23C" | NO=="23D"
replace Dyades = 24 if NO=="24A" | NO=="24B"
replace Dyades = 25 if NO=="25A" | NO=="25B"
replace Dyades = 26 if NO=="26A" | NO=="26B"
replace Dyades = 27 if NO=="27A" | NO=="27B"
replace Dyades = 28 if NO=="28A" | NO=="28B"
replace Dyades = 29 if NO=="29A" | NO=="29B"
replace Dyades = 30 if NO=="30A" | NO=="30B"
replace Dyades = 32 if NO=="32A" | NO=="32B"
replace Dyades = 33 if NO=="33A" | NO=="33B"
replace Dyades = 35 if NO=="35A" | NO=="35B"
replace Dyades = 36 if NO=="36A" | NO=="36B"
replace Dyades = 37 if NO=="37A" | NO=="37B"
replace Dyades = 38 if NO=="38A" | NO=="38B"
replace Dyades = 39 if NO=="39A" | NO=="39B"
replace Dyades = 40 if NO=="40A" | NO=="40B"
replace Dyades = 41 if NO=="41A" | NO=="41B"
replace Dyades = 421 if NO=="42A" | NO=="42B"
replace Dyades = 422 if NO=="42C" | NO=="42D"
replace Dyades = 43 if NO=="43A" | NO=="43B"
replace Dyades = 44 if NO=="44A" | NO=="44B"
replace Dyades = 45 if NO=="45A" | NO=="45B"
replace Dyades = 46 if NO=="46A" | NO=="46B"
replace Dyades = 47 if NO=="47A" | NO=="47B"
replace Dyades = 48 if NO=="48A" | NO=="48B"
replace Dyades = 49 if NO=="49A" | NO=="49B"
replace Dyades = 50 if NO=="50A" | NO=="50B"
replace Dyades = 51 if NO=="51A" | NO=="51B"
replace Dyades = 52 if NO=="52A" | NO=="52B"
replace Dyades = 53 if NO=="53A" | NO=="53B"
replace Dyades = 54 if NO=="54A" | NO=="54B"
replace Dyades = 55 if NO=="55A" | NO=="55B"
replace Dyades = 56 if NO=="56A" | NO=="56B"
replace Dyades = 571 if NO=="57A" | NO=="57B"
replace Dyades = 572 if NO=="57C" | NO=="57D"
replace Dyades = 581 if NO=="58A" | NO=="58B"
replace Dyades = 582 if NO=="58C" | NO=="58D"
replace Dyades = 59 if NO=="59A" | NO=="59B"
replace Dyades = 60 if NO=="60A" | NO=="60B"
replace Dyades = 61 if NO=="61A" | NO=="61B"
replace Dyades = 621 if NO=="62A" | NO=="62B"
replace Dyades = 622 if NO=="62C" | NO=="62D"
replace Dyades = 63 if NO=="63A" | NO=="63B"
replace Dyades = 64 if NO=="64A" | NO=="64B"
replace Dyades = 65 if NO=="65A" | NO=="65B"
replace Dyades = 66 if NO=="66A" | NO=="66B"
replace Dyades = 67 if NO=="67A" | NO=="67B"



***** Creates mean centered Voice Pitch variables (for each of the three pitch measures)
** Pitch variables
* Pitch 1 (original)
summ Pitch, detail
generate Pitch_centered = Pitch-r(mean)
summ Pitch_centered

* Pitch 2
summ Pitch_2, detail
generate Pitch_2_centered = Pitch_2-r(mean)
summ Pitch_2_centered

* Pitch 3
summ Pitch_3, detail
generate Pitch_3_centered = Pitch_3-r(mean)
summ Pitch_3_centered


*** Creates standardized pitch measures (for each of the three pitch measures)
egen Pitch_std = std(Pitch)
egen SdPitch_std = std(SdPitch)

egen Pitch_2_std = std(Pitch_2)
egen SdPitch_2_std = std(SdPitch_2)

egen Pitch_3_std = std(Pitch_3)
egen SdPitch_3_std = std(SdPitch_3)

egen Pitch_mean_std = std(Pitch_mean)


**** Creates standardized intensity measures (for each of the three pitch measures)
egen Intensity_mean = rowmean(Intensity Intensity_2 Intensity_3)
egen Intensity_mean_std = std(Intensity_mean)

egen Intensity_std = std(Intensity)
egen Intensity_2_std = std(Intensity)
egen Intensity_3_std = std(Intensity)


** Ideology
summ Score, detail
generate Score_centered = Score-r(mean)
summ Score_centered


****Correlations between pitch measures and between pitch measures and intensity
pwcorr Pitch_std Pitch_2_std Pitch_3_std Intensity_std Intensity_2_std Intensity_3_std, sig
pwcorr Pitch_mean_std Intensity_std, sig

summ Pitch_std Pitch_2_std Pitch_3_std Intensity_std Intensity_2_std Intensity_3_std
summ Pitch_mean_std Intensity_mean_std

ttest Intensity_mean_std, by(El_outcome)

*------------------------------------------------------ MAIN TEXT ANALYSES -------------------------------------------------*

*-------------------------------------------------- MAIN EFFECTS OF VOICE PITCH --------------------------------------------*

***** Effects of Pitch on Electoral Outcome (1 = winner; 0 = loser)
* DV = Electoral Outcome (1 = winner; 0 = loser)
logit El_outcome c.Pitch_mean_std c.Intensity_mean_std, cluster(Dyades)

margins, at(Pitch_mean_std=(-1 1) Intensity_mean_std=(0))

***** Effects of Pitch on Percentage of votes won
* DV = Percentage of votes won
reg Percentage c.Pitch_mean_std c.Intensity_mean_std, cluster(Dyades)

margins, at(Pitch_mean_std=(-1 1) Intensity_mean_std=(0))

****** Moderation by type of election? --> NO!
* DV = Electoral Outcome (1 = winner; 0 = loser)
logit El_outcome c.Pitch_mean_std##i.El_type c.Intensity_mean_std, cluster(Dyades)

* DV = Percentage of votes won
reg Percentage c.Pitch_mean_std##i.El_type c.Intensity_mean_std, cluster(Dyades)



*-------------------------------------------------- INTERACTIVE RELATIONSHIPS --------------------------------------------*

*-------------------------------------------------- TWO-WAY: PITCH x IDEOLOGY --------------------------------------------*
** DV: Election outcome (1 = winner; 0 = loser)
**Pitch Mean
logit El_outcome c.Pitch_mean_std##c.Score c.Intensity_mean_std, cluster(Dyades)

** DV: Percentage of Votes
**Pitch Mean
reg Percentage c.Pitch_mean_std##c.Score c.Intensity_mean_std, cluster(Dyades)


*----------------------------------------- THREE-WAY: PITCH x IDEOLOGY x ELECTION TYPE --------------------------------------*
** DV: Election outcome (1 = winner; 0 = loser)
**Pitch Mean
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std, cluster(Dyades)

margins, dydx(Pitch_mean_std) at(El_type=(0 1) Score=(4.8 6.53) Intensity_mean_std=(0))

** DV: Percentage of Votes
**Pitch Mean
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std, cluster(Dyades)

margins, dydx(Pitch_mean_std) at(El_type=(0 1) Score=(4.8 6.53) Intensity_mean_std=(0))

****** Figure 1
*** Predicting electoral outcome
*** Using MEAN PITCH as predictor variable
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std, cluster(Dyades)
summarize Pitch_mean_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_mean_std= -1 Score= 4.8 El_type=0 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=0 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53 El_type=0 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=0 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_mean_std=-1 Score= 4.8 El_type=1 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=1 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53  El_type=1 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=1 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


****** Figure 2
*** Predicting percentage of obtained votes
*** Using MEAN PITCH as predictor variable

*** Using MEAN PITCH as predictor variable
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_mean_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1) Intensity_mean_std=0)

summ Score if e(sample), detail
margins, at(Pitch_mean_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1) Intensity_mean_std=(0))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)




**************************************Robustness tests for main effects of voice pitch **********************************
****** Robustness analyses S.1: Main efefct models with separate voice pitch measures

** Predictions of election outcome

**Pitch 1
logit El_outcome c.Pitch_std c.Intensity_std, cluster(Dyades)

**Pitch 2
logit El_outcome c.Pitch_2_std c.Intensity_2_std, cluster(Dyades)

**Pitch 3
logit El_outcome c.Pitch_3_std c.Intensity_3_std, cluster(Dyades)



** Predictions of percentage of votes

**Pitch 1
reg Percentage c.Pitch_std c.Intensity_std, cluster(Dyades)

**Pitch 2
reg Percentage c.Pitch_2_std c.Intensity_2_std, cluster(Dyades)

**Pitch 3
reg Percentage c.Pitch_3_std c.Intensity_3_std, cluster(Dyades)


****** Robustness analyses S.2: Moderation by type of election using separate pitch variables
* Predictions of election outcome

**Pitch 1
logit El_outcome c.Pitch_std##i.El_type c.Intensity_std, cluster(Dyades)

**Pitch 2
logit El_outcome c.Pitch_2_std##i.El_type c.Intensity_2_std, cluster(Dyades)

**Pitch 3
logit El_outcome c.Pitch_3_std##i.El_type c.Intensity_3_std, cluster(Dyades)

* Predictions of percentage of vote
**Pitch 1
reg Percentage c.Pitch_std##i.El_type c.Intensity_std, cluster(Dyades)

**Pitch 2
reg Percentage c.Pitch_2_std##i.El_type c.Intensity_2_std, cluster(Dyades)

**Pitch 3
reg Percentage c.Pitch_3_std##i.El_type c.Intensity_3_std, cluster(Dyades)


****** Robustness analyses S.3  Does controlling for candidate incumbency change the results?
* DV = Electoral Outcome (1 = winner; 0 = loser)
**Pitch Mean
logit El_outcome c.Pitch_mean_std c.Intensity_std i.Incumbent, cluster(Dyades)


* DV = Percentage of votes won
**Pitch Mean
reg Percentage c.Pitch_mean_std c.Intensity_std i.Incumbent, cluster(Dyades)



********************************* Robustness tests for interactive effects *********************************************

****** Robustness analyses S.4: Two-way interactions between separate voice pitch measures and macro-level ideology

** DV: Election outcome (1 = winner; 0 = loser)
**Pitch 1
logit El_outcome c.Pitch_std##c.Score c.Intensity_std, cluster(Dyades)

**Pitch 2
logit El_outcome c.Pitch_2_std##c.Score c.Intensity_2_std, cluster(Dyades)

**Pitch 3
logit El_outcome c.Pitch_3_std##c.Score c.Intensity_3_std, cluster(Dyades)


** DV: Percentage of Votes
**Pitch 1
reg Percentage c.Pitch_std##c.Score c.Intensity_std, cluster(Dyades)

**Pitch 2
reg Percentage c.Pitch_2_std##c.Score c.Intensity_2_std, cluster(Dyades)

**Pitch 3
reg Percentage c.Pitch_3_std##c.Score c.Intensity_3_std, cluster(Dyades)



****** Robustness analyses S.5: Three-way interactions with separate voice pitch measures: Candidate voice pitch x macro-level ideology x type of election

** DV: Election outcome (1 = winner; 0 = loser) (reported in Table S.5.a)
**Pitch 1
logit El_outcome c.Pitch_std##c.Score##i.El_type c.Intensity_std, cluster(Dyades)

**Pitch 2
logit El_outcome c.Pitch_2_std##c.Score##i.El_type c.Intensity_2_std, cluster(Dyades)

**Pitch 3
logit El_outcome c.Pitch_3_std##c.Score##i.El_type c.Intensity_3_std, cluster(Dyades)


** DV: Percentage of Votes (reported in Table S.5.b)
**Pitch 1
reg Percentage c.Pitch_std##c.Score##i.El_type c.Intensity_std, cluster(Dyades)

**Pitch 2
reg Percentage c.Pitch_2_std##c.Score##i.El_type c.Intensity_2_std, cluster(Dyades)

**Pitch 3
reg Percentage c.Pitch_3_std##c.Score##i.El_type c.Intensity_3_std, cluster(Dyades)


**------------------------- Figures using separate pitch variables for three-way interaction on ELECTION OUTCOME --------------------------**

*** Using FIRST PITCH MEASURE as predictor variable (Figure 5.a, panel a)
logit El_outcome c.Pitch_std##c.Score##i.El_type c.Intensity_std, cluster(Dyades)
summarize Pitch_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_std= -1 Score= 4.8 El_type=0 Intensity_std=0) /// 
at(Pitch_std= 1 Score= 4.8 El_type=0 Intensity_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_std= -1 Score= 6.53 El_type=0 Intensity_std=0)  ///
at(Pitch_std= 1 Score= 6.53 El_type=0 Intensity_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_std=-1 Score= 4.8 El_type=1 Intensity_std=0) /// 
at(Pitch_std= 1 Score= 4.8 El_type=1 Intensity_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_std= -1 Score= 6.53  El_type=1 Intensity_std=0)  ///
at(Pitch_std= 1 Score= 6.53 El_type=1 Intensity_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


*** Using SECOND PITCH MEASURE as predictor variable (Figure 5.a, panel b)
logit El_outcome c.Pitch_2_std##c.Score##i.El_type c.Intensity_2_std, cluster(Dyades)
summarize Pitch_2_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_2_std= -1 Score= 4.8 El_type=0 Intensity_2_std=0) /// 
at(Pitch_2_std= 1 Score= 4.8 El_type=0 Intensity_2_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_2_std= -1 Score= 6.53 El_type=0 Intensity_2_std=0)  ///
at(Pitch_2_std= 1 Score= 6.53 El_type=0 Intensity_2_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_2_std=-1 Score= 4.8 El_type=1 Intensity_2_std=0) /// 
at(Pitch_2_std= 1 Score= 4.8 El_type=1 Intensity_2_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_2_std= -1 Score= 6.53  El_type=1 Intensity_2_std=0)  ///
at(Pitch_2_std= 1 Score= 6.53 El_type=1 Intensity_2_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


*** Using THIRD PITCH MEASURE as predictor variable (Figure 5.a, panel c)
logit El_outcome c.Pitch_3_std##c.Score##i.El_type c.Intensity_3_std, cluster(Dyades)
summarize Pitch_3_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_3_std= -1 Score= 4.8 El_type=0 Intensity_3_std=0) /// 
at(Pitch_3_std= 1 Score= 4.8 El_type=0 Intensity_3_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_3_std= -1 Score= 6.53 El_type=0 Intensity_3_std=0)  ///
at(Pitch_3_std= 1 Score= 6.53 El_type=0 Intensity_3_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_3_std=-1 Score= 4.8 El_type=1 Intensity_3_std=0) /// 
at(Pitch_3_std= 1 Score= 4.8 El_type=1 Intensity_3_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_3_std= -1 Score= 6.53  El_type=1 Intensity_3_std=0)  ///
at(Pitch_3_std= 1 Score= 6.53 El_type=1 Intensity_3_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


**------------------------------ Figures for three-way interaction on PERCENTAGE OF VOTES ----------------------------------------**

*** Using FIRST PITCH MEASURE as predictor variable (Figure 5.b, panel a)
reg Percentage c.Pitch_std##c.Score##i.El_type c.Intensity_std, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1) Intensity_std=(0))

summ Score if e(sample), detail
margins, at(Pitch_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)


*** Using SECOND PITCH MEASURE as predictor variable (Figure 5.b, panel b)
reg Percentage c.Pitch_2_std##c.Score##i.El_type c.Intensity_2_std, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_2_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))

summ Score if e(sample), detail
margins, at(Pitch_2_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)


*** Using THIRD PITCH MEASURE as predictor variable (Figure 5.b, panel c)
reg Percentage c.Pitch_3_std##c.Score##i.El_type c.Intensity_3_std, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_3_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))

summ Score if e(sample), detail
margins, at(Pitch_3_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)



**------------------------------ Robustness tests for interactive effects CONTINUED ----------------------------------------**

****** Robustness analyses S.6: Three-way interactions (pitch x ideology x election type) controlling for incumbency 

** DV: Election outcome (1 = winner; 0 = loser) (reported in Table S.6, model 1)
**Pitch Mean
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std i.Incumbent, cluster(Dyades)

*** Illustration based on MEAN PITCH MEASURE (Figure 6, panel a)
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std i.Incumbent, cluster(Dyades)
summarize Pitch_mean_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_mean_std= -1 Score= 4.8 El_type=0 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53 El_type=0 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_mean_std=-1 Score= 4.8 El_type=1 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=1) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53  El_type=1 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=1) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


** DV: Percentage of Votes (reported in Table S.6, model 2)

**Pitch Mean
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std i.Incumbent, cluster(Dyades)
eststo Model_mean

*** Illustration based on MEAN PITCH MEASURE (Figure 6, panel b)
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std i.Incumbent, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_mean_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))

summ Score if e(sample), detail
margins, at(Pitch_mean_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)



****** Robustness analyses S.7: Three-way interactions (pitch x ideology x election type) controlling for three-way interaction with voice intensity 

** DV: Election outcome (1 = winner; 0 = loser) (reported in Table S.7, model 1)
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std##c.Score##i.El_type, cluster(Dyades)

** DV: Percentage of Votes (reported in Table S.7, model 2)
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std##c.Score##i.El_type, cluster(Dyades)


*** Illustration based on MEAN PITCH MEASURE (Figure 7, panel a)
logit El_outcome c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std##c.Score##i.El_type, cluster(Dyades)
summarize Pitch_mean_std, detail
summarize Score, detail

*Presidential elections
margins, at(Pitch_mean_std= -1 Score= 4.8 El_type=0 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & Presidential") scheme(s2mono) name(left_Pres_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53 El_type=0 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & Presidential") scheme(s2mono) name(right_Pres_pred_prob, replace)

*General elections
margins, at(Pitch_mean_std=-1 Score= 4.8 El_type=1 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score= 4.8 El_type=1) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Left-leaning & General") scheme(s2mono) name(left_general_pred_prob, replace)

margins, at(Pitch_mean_std= -1 Score= 6.53  El_type=1 Intensity_mean_std=0)  ///
at(Pitch_mean_std= 1 Score= 6.53 El_type=1) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.1) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Right-leaning & General") scheme(s2mono) name(right_general_pred_prob, replace)

graph combine left_Pres_pred_prob right_Pres_pred_prob left_general_pred_prob right_general_pred_prob


*** Illustration based on MEAN PITCH MEASURE (Figure 7, panel b)
reg Percentage c.Pitch_mean_std##c.Score##i.El_type c.Intensity_mean_std##c.Score##i.El_type, cluster(Dyades)
summ Score if e(sample), detail
margins, dydx(Pitch_mean_std) at(Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1) Intensity_mean_std=(0))

summ Score if e(sample), detail
margins, at(Pitch_mean_std=(-2 (0.5) 2) Score=(`r(p10)' `r(p50)' `r(p90)') El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(3 2 1) label(1 "left-leaning country (10th percentile)") label(2 "Median country (50th percentile)") label(3 "right-leaning country (90th percentile)")) ///
by(El_type) scheme(s1mono)



****** Robustness analyses S.8: Three-way interactions (pitch x ideology x election type) using dichotomous measure of national-level ideology 
* Creates median split variable for national-level ideology
generate Score_median=.
replace Score_median = 0 if Score < 5.59
replace Score_median = 1 if Score >= 5.59


*** Estimations models with median split across presidential and general elections for country-level ideology rather than the continuous variable:

** DV: Election outcome (1 = winner; 0 = loser) (reported in Table S.8, model 1)
logit El_outcome c.Pitch_mean_std##i.Score_median##i.El_type c.Intensity_mean_std, cluster(Dyades)


*** Illustration based on MEAN PITCH MEASURE (Figure 8, panel a)

margins, at(Pitch_mean_std=-1 Score_median=0 El_type=0 Intensity_mean_std=0) /// 
at(Pitch_mean_std=1 Score_median=0 El_type=0 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.2) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Presidential elections") scheme(s2mono) name(lib_presidential_mediansplit, replace)

margins, at(Pitch_mean_std=-1 Score_median=1 El_type=0 Intensity_mean_std=0) /// 
at(Pitch_mean_std=1 Score_median=1 El_type=0 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.2) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Presidential elections") scheme(s2mono) name(cons_presidential_mediansplit, replace)

margins, at(Pitch_mean_std=-1 Score_median=0 El_type=1 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score_median=0 El_type=1 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.2) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Parliamentary elections") scheme(s2mono) name(lib_parliamentary_mediansplit, replace)

margins, at(Pitch_mean_std=-1 Score_median=1 El_type=1 Intensity_mean_std=0) /// 
at(Pitch_mean_std= 1 Score_median=1 El_type=1 Intensity_mean_std=0) 
marginsplot, level(95) recast(bar) recastci(rcap) ylabel(0 (0.2) 1) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for winning election") nolabels ///
title("Parliamentary elections") scheme(s2mono) name(cons_parliamentary_mediansplit, replace)

graph combine lib_presidential_mediansplit cons_presidential_mediansplit lib_parliamentary_mediansplit cons_parliamentary_mediansplit


** DV: Percentage of votes won (reported in Table S.8, model 2)
reg Percentage c.Pitch_mean_std##i.Score_median##i.El_type c.Intensity_mean_std, cluster(Dyades)


*** Illustration based on MEAN PITCH MEASURE (Figure 8, panel b)

reg Percentage c.Pitch_mean_std##i.Score_median##i.El_type c.Intensity_mean_std, cluster(Dyades)

summ Score if e(sample), detail
margins, at(Pitch_mean_std=(-2 (0.5) 2) Score_median=(0 1) El_type=(0 1))
marginsplot, noci recast(line) ytitle("Predicted percentage of votes") xtitle("Pitch (standardized)") title("") ylabel(0 (10) 100) ///
legend(order(2 1) label(1 "Liberal country (Below median ideology") label(2 "Conservative country (Above median ideology)")) ///
by(El_type) scheme(s1mono)


